package com.example.asus.keshe;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



/**
 * Created by k42 on 2018-05-05.
 */

public class RegisterActivity extends Activity implements View.OnClickListener{

    private MySqliteHelper mySqliteHelper;

    private EditText editText,editText1;

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);

        editText = (EditText)findViewById(R.id.editText3);
        editText1 = (EditText)findViewById(R.id.editText4);

        mySqliteHelper = new MySqliteHelper(this);

        button = (Button)findViewById(R.id.button7);

        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String username = editText.getText().toString();
        String password = editText1.getText().toString();

        SQLiteDatabase db =  mySqliteHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("name",username);
        values.put("password",password);

        db.insert("person",null,values);//插入数据库

        Toast.makeText(this,"注册成功",Toast.LENGTH_LONG).show();
        Intent intent =new Intent();
        intent.setClass(RegisterActivity.this,LoginActivity.class);
        startActivity(intent);

    }
}

